<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/wx/msg/mass/addNews/${wxid!}"  data-toggle="modal" data-target="#dialogDetail"><i class="ti-plus"></i> 添加图文</a>
        <a class="btn btn-primary navbar-btn" href="${base}/platform/wx/msg/mass/${wxid!}" data-pjax><i
                class="ti-angle-left"></i> 返回</a>
    </div>
</header>
<div class=panel-body style="padding-top: 50px;">
    <div class="table-responsive no-border">
        <table class="table table-bordered table-striped mg-t datatable">
            <thead>
            <tr>
                <th>标题</th>
                <th>创建时间</th>
                <th>操作</th>
        </table>
    </div>
</div>
<div id="dialogDelete" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">删除</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        删除后无法恢复，确定删除吗？ <br/>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button id="ok" type="button" class="btn btn-primary" data-loading-text="正在删除...">确 定</button>
            </div>
        </div>
    </div>
</div>
<div id="dialogDetail" class="modal fade bs-modal" tabindex="-3" role="dialog" aria-hidden="true">
    <div class="modal-dialog" style="min-width: 850px;">
        <div class="modal-content" style="min-width: 850px;">
        </div>
    </div>
</div>
<script language="JavaScript">
    var datatable;
    function initDatatable() {
        datatable = $('.datatable').DataTable({
            "dom": '<"toolbar">frtip',
            "searching": false,
            "processing": false,
            "serverSide": true,
            "select": true,
            "ordering": true,
            "language": {
                "url": "${base}/assets/plugins/datatables/cn.json"
            },
            "preDrawCallback": function () {
                sublime.showLoadingbar($(".main-content"));
            },
            "drawCallback": function () {
                sublime.closeLoadingbar($(".main-content"));
            },
            "ajax": {
                "url": "${base}/platform/wx/msg/mass/newsData/${wxid!}",
                "type": "post",
                "data": function (d) {
                }
            },
            "order": [[1, "desc"]],
            "columns": [
                {"data": "title", "bSortable": true},
                {"data": "opAt", "bSortable": true}
            ],
            "columnDefs": [
                {
                    "render": function (data, type, row) {
                        if (data) {
                            return moment(parseInt(data*1000)).format("YYYY-MM-DD HH:mm:ss");
                        }
                        return '';
                    },
                    "targets": 1
                },
                {
                    "render": function (data, type, row) {
                        return '<div class="btn-group"><button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">' +
                                ' <i class="ti-settings"></i> <span class="ti-angle-down"></span></button><ul class="dropdown-menu" role="menu">'+
                                '<li><a href="${base}/platform/wx/msg/mass/newsDetail/' + row.id + '"  data-toggle="modal" data-target="#dialogDetail">查看</a></li>'+
                                '<li><a href="javascript:;" onclick="del(\''+row.id+'\')">删除</a></li>'+
                                '</ul></div>';
                    },
                    "targets": 2
                }
            ]
        });
        datatable.on('click', 'tr', function () {
            $(this).toggleClass('selected');
        });
    }
    function del(id) {
        var dialog = $("#dialogDelete");
        dialog.modal("show");
        dialog.find("#ok").unbind("click");
        dialog.find("#ok").bind("click", function (event) {
            var btn = $(this);
            btn.button("loading");
            $.post("${base}/platform/wx/msg/mass/deleteNews/" + id, {}, function (data) {
                if (data.code == 0) {
                    datatable.ajax.reload(null,false);
                } else {
                    Toast.error(data.msg);
                }
                //重置按钮状态，关闭提示框
                btn.button("reset");
                dialog.modal("hide");
            }, "json");
        });
    }
    $(function () {
        initDatatable();
        $("#dialogDetail").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
        });
    });
</script>

<%}%>